﻿@model planerka.DataAccess.Models.project
@using planerka.Common.Enums; 
@using planerka.Common;   
@using planerka.DataAccess.DataService;       
@using planerka.DataAccess.Models;
@{bool rightsEdit  = Model.rightsEditDelete;

  Dictionary<String, Object> htmlAttribs = new Dictionary<string, object>();

  string readonlyClass = "";
 
  if (!rightsEdit)
  {
   
    readonlyClass = "readonly";
   
  }
}

<script src="@Url.Content("~/Scripts/ui/jquery.ui.core.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/ui/jquery.ui.widget.js")" type="text/javascript"></script>

<link rel="stylesheet" href="@Url.Content("~/Content/jquery.ui.theme-overcast.css")" type="text/css" />

<link rel="stylesheet" href="@Url.Content("~/Content/jquery.ui.datepicker.css")"  type="text/css" />
<link rel="stylesheet" href="@Url.Content("~/Content/jquery.ui.core.css")"  type="text/css" />
<script type="text/javascript" src="@Url.Content("~/Scripts/ui/jquery.ui.datepicker.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ui/jquery.ui.datepicker-ru.js")"></script>

 <script type="text/javascript">


     // стереть ResultMessage
     function closeResultMessage() {
         $(".resultMessage").html("");
     }

     $(function () {

         setTimeout('closeResultMessage()', 3000);

         $.datepicker.setDefaults($.datepicker.regional[""]);
         $(".dateField").datepicker($.datepicker.regional["ru"]);

         // меняем цвет фона для статуса проекта
         $("#projectStatus").change(function () {

             var projectStatusID = $(this)[0].value; // get value
             $(this).parent().removeClass('projectStatus1 projectStatus2 projectStatus3 projectStatus4');
             $(this).parent().addClass('projectStatus' + projectStatusID);
             
         });
     });

</script>
<span class="resultMessage">@Html.Raw(ViewData["resultMessage"] != null ? ("<span>" + ViewData["resultMessage"] + "</span>") : "")</span> 
@using (Html.BeginForm("projectDetails", "tm"))
{
 <div class="editItem @readonlyClass" style="margin-bottom: 100px;">
    @Html.ValidationSummary(true)

     <h2 style="float: left;">@ViewData["caption"]</h2>
     @if (rightsEdit)
     {     <input type="submit" value="Сохранить" class="save" /> }
     <div class="clear"></div>
     
    
    <fieldset class="fieldsetEdit" style="width: 800px;">
        <input id="ID" type="hidden" name="ID" value="@Model.ID" />
       @* @Html.HiddenFor(model => model.ID)*@
        <div class="editor-label">
            Наименование проекта
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.projectName,
         rightsEdit ? (object)new { @class = "projectTextBox" } : (object)new { @class = "projectTextBox", @readonly = "readonly" })
            @Html.ValidationMessageFor(model => model.projectName)
        </div>

        <div class="editor-label">
            Описание проекта
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.projectDescription,
                rightsEdit ? (object)new { @class = "projectTextBox", style = "height: 140px;" } : (object)new { @class = "projectTextBox", style = "height: 140px;", @readonly = "readonly" })
            
            @Html.ValidationMessageFor(model => model.projectDescription)
        </div>

        @{
       List<SelectListItem> stList = new List<SelectListItem>();
       stList = planerka.Common.tools.getEnumSelectList<projectStatuses>().ToList();

       string projectStatus = "";
       if (Enum.IsDefined(typeof(projectStatuses), Model.projectStatus))
       {
           projectStatus = ((projectStatuses)Model.projectStatus).ToString();
       }

       string projectStatusClass = "projectStatus" + Model.projectStatus;
          } 
        <div class="oneThird">
        <div class="editor-label divInputs">
            Статус проекта: 
         </div> 
        <div class="editor-field divInputs @projectStatusClass">
          @Html.DropDownList("projectStatus", new SelectList(stList, "Value", "Text", Model.projectStatus),
            rightsEdit ? (object)new { @class = "filterInputs" } : (object)new { @class = "filterInputs", @readonly = "readonly" })
         
        </div>

       </div>

       <div class="oneThird">
        <div class="editor-label divInputs">
            Приоритет
        </div>
        <div class="editor-field divInputs">
        @{
     stList = new List<SelectListItem>();
     stList = planerka.Common.tools.getEnumSelectList<priorities>().ToList();
          } 
            @Html.DropDownList("priority", new SelectList(stList, "Value", "Text", Model.priority),
                    rightsEdit ? (object)new { @class = "filterInputs" } : (object)new { @class = "filterInputs", @readonly = "readonly" })
            
        </div>
        </div>

        <div class="oneThird">
       <div class="editor-label">
            Заказчик
        </div>
        <div class="editor-field">
            @{
       UserService userService = new UserService();
       user currentUser = userService.getCurrentUser();
       List<SelectListItem> userList = userService.getUserList(currentUser.UserId).Where(p => p.isCustomer 
           || (p.isEmailApproved && p.ID != currentUser.ID)).Select(p => new SelectListItem { Text = p.nameView, Value = p.ID.ToString() }).ToList();
       userList.Insert(0, new SelectListItem { Text = "", Value = "0" });
            }
            @Html.DropDownList("projectCustomer_ID", new SelectList(userList, "Value", "Text", Model.customer_ID),
         rightsEdit ? (object)new { @class = "filterInputs", style = "width: 280px;" } : (object)new { @class = "filterInputs", @readonly = "readonly", style = "width: 280px;" })
            
        </div>
        </div>

        <div class="clear" style="padding: 10px 0px !important;"></div>
        <div class="oneHalf">
        <div class="editor-label">
            Веб-страница проекта
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.projectHttp,
            rightsEdit ? (object)new { @class = "projectTextBox" } : (object)new { @class = "projectTextBox", @readonly = "readonly" })
            @Html.ValidationMessageFor(model => model.projectHttp)
        </div>
        </div>
       
       
        <div class="clear"></div>

        <fieldset style="border: 1pt solid #ddd; padding: 10px;  width: 760px;">
       
            <table>
                <tr>
                    <td class="editor-label">План старт&nbsp;</td>
                    <td style="width: 160px;">
                        @Html.TextBox("planStartString", tools.getStringFromNullableDateTime(Model.planStart),
                            rightsEdit ? (object)new { @class = "dateField" } : (object)new { @class = "dateField", @readonly = "readonly" })
                        
                        </td>
                    <td class="editor-label">План финиш&nbsp;</td>
                    <td style="width: 160px;">
                        @Html.TextBox("planFinishString", tools.getStringFromNullableDateTime(Model.planFinish),
                            rightsEdit ? (object)new { @class = "dateField" } : (object)new { @class = "dateField", @readonly = "readonly" })
                        
                    </td>
                    <td class="editor-label">
                    @if (Model.planStart != null && Model.planFinish != null)
                    {
                        @:всего дней: @(((DateTime)Model.planFinish).Subtract((DateTime)Model.planStart).Days)
                    }
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">Факт старт&nbsp;</td>
                    <td>
                        @Html.TextBox("factStartString", tools.getStringFromNullableDateTime(Model.factStart),
                            rightsEdit ? (object)new { @class = "dateField" } : (object)new { @class = "dateField", @readonly = "readonly" })
                        
                        </td>
                    <td class="editor-label">Факт финиш&nbsp;</td>
                    <td>
    
                        @Html.TextBox("factFinishString", tools.getStringFromNullableDateTime(Model.factFinish),
                        rightsEdit ? (object)new { @class = "dateField" } : (object)new { @class = "dateField", @readonly = "readonly" }) 
                        
                    </td>
                    <td class="editor-label">
                        @if (Model.factStart != null && Model.factFinish != null)
                        {
                        @:всего дней: @(((DateTime)Model.factFinish).Subtract((DateTime)Model.factStart).Days)
                    }
                    </td>
                </tr>
            </table>

        </fieldset>

        
    </fieldset>

    </div>
}



